package com.itheima.handler;

import com.itheima.exception.ConsumerException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.security.auth.login.Configuration;

/**
 * @author Hakuna Matata
 * @date 2022-10-11-17:04
 */

@RestControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(ConsumerException.class)
    public ResponseEntity consumerException(ConsumerException ce) {
        ce.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ce.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity exception(Exception e){
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("系统异常");
    }
}
